home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / AwaitConnect / Main.c < prev    next >
C/C++ Source or Header  |  1996-10-31  |  7KB  |  255 lines

  1. /*
  2.    Await Connect Door for HBBS (C) 1995 Hydra/LSD
  3.  
  4.    function of the "AWAIT" door
  5.    ============================
  6.  
  7.    - display "Await" screen
  8.    - check for incoming calls
  9.      - set N_ND->ConnectBaud accordingly.
  10.    - check for local logins
  11.      - set N_ND->ConnectBaud to "LOCAL"
  12.    - check for shutdown requests
  13.    - set N_ND->LoginType correctly
  14.  
  15.    todo
  16.    ====
  17.  
  18.    Make await door aware of when the user opens/closes the watch window
  19.    and display the "Await" Special Screen when they open the window.
  20.  
  21. */
  22.  
  23. #include <exec/types.h>
  24. #include <exec/memory.h>
  25.  
  26. #include <dos/dos.h>          // JUST so we can call SetProgramName()
  27. #include <clib/dos_protos.h>
  28.  
  29. #include <clib/exec_protos.h>
  30. #include <clib/alib_protos.h>
  31.  
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. #include <time.h>
  37.  
  38.  
  39. #ifdef __SASC
  40. int CXBRK(void) { return(0); }
  41. int _CXBRK(void) { return(0); }
  42. void chkabort(void) {}
  43. #endif
  44.  
  45. #include <HBBS/ANSI_Codes.h>
  46. #include <HBBS/Defines.h>
  47. #include <HBBS/types.h>
  48. #include <HBBS/structures.h>
  49. #include <HBBS/hbbscommon_protos.h>
  50. #include <HBBS/hbbscommon_pragmas.h>
  51. #include <HBBS/Hbbsnode_protos.h>
  52. #include <HBBS/Hbbsnode_pragmas.h>
  53. #include <HBBS/release.h>
  54. char *versionstr="$VER: AwaitConnect "RELEASE_STR;
  55.  
  56. extern struct Library *DOSBase;
  57. extern struct Library *SysBase;
  58. struct Library *HBBSCommonBase=NULL;
  59. struct Library *HBBSNodeBase=NULL;
  60.  
  61. struct BBSGlobalData *BBSGlobal=NULL;
  62. struct NodeData *N_ND=NULL;
  63. int N_NodeNum=-1;
  64. UBYTE *str_CRLF="\n\r\0";
  65.  
  66. static VOID cleanup(ULONG num)
  67. {
  68.   if (HBBSNodeBase)
  69.   {
  70.     HBBS_CleanUpDoor();
  71.     CloseLibrary (HBBSNodeBase);
  72.   }
  73.  
  74.   if (HBBSCommonBase)
  75.   {
  76.     HBBS_CleanUpCommon();
  77.     CloseLibrary (HBBSCommonBase);
  78.   }
  79.  
  80.   if (num) printf("Door Error = %d\n",num);
  81.  
  82.   exit(0);
  83. }
  84.  
  85. static VOID init(char *name)
  86. {
  87.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  88.   {
  89.     cleanup(1);
  90.   }
  91.  
  92.   if (!(HBBS_InitCommon()))
  93.   {
  94.     cleanup(2);
  95.   }
  96.  
  97.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  98.   {
  99.     cleanup(3);
  100.   }
  101.  
  102.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  103.   {
  104.     cleanup(4);
  105.   }
  106.   SetProgramName(name);
  107. }
  108.  
  109. V_BOOL CheckModemConnectStr( void )
  110. {
  111.   V_BOOL retval=FALSE;
  112.   struct Node *nd;
  113.   short tmpval1,tmpval2;
  114.  
  115.   for (nd = N_ND->NodeDevice.RelaxedConnectStr->lh_Head ; nd->ln_Succ ; nd = nd->ln_Succ)
  116.   {
  117.     if (nd->ln_Name)
  118.     {
  119.       if (iposition(nd->ln_Name,N_ND->CurrentLine)>=0)
  120.       {
  121.         retval=TRUE;
  122.         // ok, get the baud rate from the connect string!
  123.         tmpval1=iposition(" ",N_ND->CurrentLine);
  124.         tmpval2=iposition("/",N_ND->CurrentLine)-1; // miss out the "/"
  125.         if (tmpval1 >= 0)
  126.         {
  127.           tmpval1++; // miss out the " "
  128.           if (tmpval2 <0)
  129.           {
  130.             tmpval2=strlen(N_ND->CurrentLine)-1;
  131.           }
  132.           if (tmpval2>tmpval1)
  133.           {
  134.             strftcpy(N_ND->ConnectBaud,N_ND->CurrentLine,tmpval1,tmpval2);
  135.           }
  136.         }
  137.         else // can't determine connect speed, so set to 28800 so doors don't get confused by a blank string!
  138.         {
  139.           strcpy(N_ND->ConnectBaud,"28800");
  140.         }
  141.       }
  142.     }
  143.   }
  144.   return(retval);
  145. }
  146.  
  147. void CheckModemIncomingStr( void )
  148. {
  149.   if (N_ND->NodeDevice.Incoming!=NULL && iposition(N_ND->NodeDevice.Incoming,N_ND->CurrentLine)>=0)
  150.   {
  151.     DOOR_SysopText("Incoming Call...\r\n");
  152.   }
  153. }
  154.  
  155. void DisplayAwaitScreen( void )
  156. {
  157.   if (!DOOR_DisplaySpecialScreen("Await")) // Display Await Screen..
  158.   {
  159.     DOOR_SysopText(ANSI_RESET ANSI_FG_CYAN
  160.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F1" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Local Login\n\r"
  161.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F2" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Initialise Modem\n\r"
  162.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F3" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Answer Modem Now\n\r"
  163.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F5" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Toggle modem Debug\n\r"
  164.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F7" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Close Watch Window/Screen\n\r"
  165.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F8" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Toggle Watch between Screen or Window\n\r"
  166.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F9" ANSI_FG_PURPLE "] " ANSI_FG_WHITE " - " ANSI_FG_GREEN "Terminal Door\n\r"
  167.                    ANSI_FG_PURPLE "  [" ANSI_FG_WHITE "F10" ANSI_FG_PURPLE "]" ANSI_FG_WHITE " - " ANSI_FG_GREEN "Shutdown This Node\n\r\r\n"
  168.                    "Awaiting Connect ....\r\n");
  169.   }
  170. }
  171.  
  172.  
  173. void DoorMain( void )
  174. {
  175.   ULONG getlinestatus;
  176.  
  177.   DisplayAwaitScreen();
  178.   do
  179.   {
  180.     N_ND->LoginType=LOGIN_NONE;
  181.  
  182.     getlinestatus=DOOR_GetLine(GL_NONE,'\0',0,0,NULL);
  183.     DOOR_SysopText(N_ND->CurrentLine);
  184.     DOOR_SysopText(str_CRLF);
  185.     switch (getlinestatus)
  186.     {
  187.       case IN_LOGIN:
  188.         N_ND->LoginType=LOGIN_LOCAL;
  189.         break;
  190.       case IN_IMMEDIATE:
  191.         DOOR_WriteSerText(N_ND->NodeDevice.ImmediateAnswer);
  192.         DOOR_WriteSerText("\n\r");
  193.         break;
  194.       case IN_TERMINAL:
  195.         DOOR_SysopText("This will run a terminal door using the bbs's setup\n\r"
  196.                        "It'll save you having to close the node down to run\n\r"
  197.                        "A comms program!\n\r");
  198.         break;
  199.       case IN_GOTLINE:
  200.         if (!N_ND->NodeDevice.NullModemCable)
  201.         {
  202.           CheckModemIncomingStr();
  203.           if (CheckModemConnectStr()) N_ND->LoginType=LOGIN_REMOTE;
  204.         }
  205.         else
  206.         {
  207.           DOOR_WriteSerText("CONNECT\r\n");
  208.           strcpy(N_ND->ConnectBaud,"LOCAL");
  209.           N_ND->LoginType=LOGIN_REMOTE;
  210.         }
  211.         break;
  212.       case IN_SHUTDOWN:
  213.         N_ND->RequestShutdown=TRUE;
  214.         break;
  215.       case IN_DISPLAYAWAIT:
  216.         DisplayAwaitScreen();
  217.         break;
  218.       case IN_DIALOUT:
  219.         DOOR_SysopText("Enter Number > ");
  220.         N_ND->LoginType=LOGIN_LOCAL;
  221.         if (IN_GOTLINE==DOOR_GetLine(GL_SYSOP|GL_EDIT|GL_DISPLAY,'\0',0,0,NULL))
  222.         {
  223.           if (N_ND->CurrentLine[0])
  224.           {
  225.             DOOR_WriteSerText("ATDT");
  226.             DOOR_WriteSerText(N_ND->CurrentLine);
  227.             DOOR_WriteSerText("\r\n");
  228.           }
  229.         }
  230.         N_ND->LoginType=LOGIN_NONE;
  231.         break;
  232.  
  233.     }
  234.   } while (N_ND->RequestShutdown==FALSE && N_ND->LoginType==LOGIN_NONE);
  235. }
  236.  
  237. int main(int argc,char *argv[])
  238. {
  239.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  240.   {
  241.     printf("Invalid/No Paramaters for door!\n");
  242.     exit (20);
  243.   }
  244.   init("Awaiting Connect");
  245.  
  246.   if (BBSGlobal=HBBS_GimmeBBS())
  247.   {
  248.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  249.     {
  250.       DoorMain();
  251.     }
  252.   }
  253.   cleanup(0);
  254. }
  255.